<?php
session_start();
if (!isset($_SESSION['user']) || !isset($_SESSION['Adimn'])) {
    exit;
}

if (!isset($_POST['do'])) {
    exit;
}
?>
<script src="inc/js/core.js" type="text/javascript"></script>
<script>
    $(function() {
        $("#catalog").accordion();
        $("#catalog li").draggable({
            appendTo: "body",
            helper: "clone"
        });
        $("#cart ol").droppable({
            activeClass: "ui-state-default",
            hoverClass: "ui-state-hover",
            accept: ":not(.ui-sortable-helper)",
            drop: function(event, ui) {
                $(this).find(".placeholder").remove();
                $("<li></li>").text(ui.draggable.text()).appendTo(this);
                $("<input name='list[]' type='hidden' /> ").val(ui.draggable.val()).appendTo(this);
          },
        }).sortable({
            items: "li:not(.placeholder)",
            sort: function() {
                // gets added unintentionally by droppable interacting with sortable
                // using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
                $(this).removeClass("ui-state-default");
            }

        });


    });






</script>
<?php
require ('./inc/database.php');
require ('./inc/functions.php');
require_once('./class/class.phpmailer.php');
require_once('./class/class.user.php');
require_once('./class/class.project.php');
require_once('./class/class.task.php');
require_once('./class/class.project_access_details.php');
require_once('./class/class.permissions.php');
require_once('./class/class.comments.php');
require_once('./class/class.dashboard.php');
require_once('./class/baseDB.php');
require_once('./class/class.customer.php');
require_once('./config.php');

db_connect();
?>
<?php
/* Admin */
if ($_POST['do'] == 'goto_control_panel') {//מחזיר את הדף ניהול
    if (isset($_SESSION['Adimn'])) {
        dashboard::get_html_bash();
        ?>
        <!--new_user-->   
        <div id="new_user" class="box_div right_div  ">
            <span class="color_turkiz title tl ">יצירת משתמש חדש</span>
            <div>
                <a class="btn_a" id="btn_new_user" title="צור"></a>
                <span class="icon"></span>
            </div>
        </div>
        <!--edit_user-->   
        <div id="edit_user" class="box_div">
            <span class="color_turkiz title tl " >עריכת משתמש</span>
            <div >

                <span id="people_icon" ></span>
                <span class="icon"></span>
                <select id="customer">
                    <option value="none" selected="selected">לקוח</option>
        <?php get_customer(); ?>
                </select>
                <select id="user_name">
                    <option value="none">שם משתמש</option>
                </select>
                <a class="btn_a info_link " id="btn_edit_user" >ערוך</a>
            </div>
        </div>
        <!--new_project-->   
        <div id="new_project" class="box_div right_div">
            <span  class="color_turkiz title tl " > יצירת פרויקט חדש</span>
            <div>
                <a class="btn_a" id="btn_new_project" title="צור"></a>   
                <span id="briefcase_icon"></span>  
            </div>    
        </div>
        <!-----------------------------------------------------------edit_project------------------------------------->   
        <div id="edit_project" class="box_div">
            <span  class="color_turkiz title tl " >עריכת פרויקט</span>
            <div>
                <span class="icon"></span>
                <span id="briefcase_icon" ></span>
                <select id="customer" >
                    <option value="none" selected="selected">לקוח</option>
        <?php get_customer(); ?>
                </select>
                <select id="project">
                    <option>פרויקט</option>
                </select>
                <a class="btn_a info_link" id="btn_edit_project" >ערוך</a>
            </div>  
        </div>

        <!--new_customer--> 
        <div id="new_customer" class="box_div right_div">
            <span class="color_turkiz title tl " >יצירת לקוח חדש</span>
            <div>
                <a class="btn_a" id="btn_new_customer" title="צור" ></a>
                <span class="icon"></span> 
            </div>
        </div>
        <!--edit_customer--> 
        <div id="edit_customer" class="box_div">
            <span class="color_turkiz title tl ">עריכת לקוח</span>
            <div>
                <span class="icon"></span>
                <span id="customer_icon"></span>
                <select id="customer" name="customer">
                    <option value="none" >לקוח</option>
        <?php get_customer(); ?>
                </select>
                <a class="btn_a info_link" id="btn_edit_customer">ערוך</a>
            </div>
        </div>
        <div id="LookProfilCustomer" class="box_div">
            <span class="color_turkiz title tl ">צפיה בפרטי לקוח</span>
            <div>
                <span class="icon"></span>
                <span id="customer_icon"></span>
                <select id="customer" name="customer">
                    <option value="none" >לקוח</option>
        <?php get_customer(); ?>
                </select>
                <a class="btn_a info_link" id="btn_LookProfilCustomer">לצפייה</a>
            </div>
        </div>
        <!---div_form--->
        <div id="div_form"> 




            <!-- <div id="error" >עליך למלא את כל השדות</div>
             </div>
             <script src="inc/js/jquery.validate.js" type="text/javascript"></script>
          <script>
                            jQuery.validator.addMethod("selectNone", 
                             function(value, element) { 
                                   if (element.value == "none") 
                                   { 
                                     return false; 
                                   } 
                                   else return true; 
                             }, 
                     "Please select an option." 
                     ); 

           </script>-->
            <script>


                $(document).ready(function(e) {







                    /*change*/
                    $('#edit_project #customer').change(function() {
                        var temp = $('#edit_project #customer').val();
                        change_edit_project(temp);
                    });
                    $('#edit_user #customer').change(function() {
                        var temp = $('#edit_user #customer').val();
                        if (temp != 'none')
                        {
                            change_edit_user(temp);
                        }
                    });
                    $('#form_set #customer_add ').change(function() {

                        var temp = $('#form_new_user #customer_add').val();
                        alert(temp);
                        change_new_user(temp);
                    });


                    /*display none*/
                    $('#new_project').click(function() {

                        get_new_form_project();
                    });
                    $('#new_user').click(function() {
                        get_new_form_user();
                    });
                    $('#new_customer').click(function() {
                        get_new_form_customer();
                    });

                    /*click edit*/
                    $('#btn_edit_project').click(function() {
                        if ($("#edit_project #customer").val() != 'none' && $('#edit_project #project').val() != 'none')
                        {
                            get_info_project($('#edit_project #project').val());
                        }
                    });
                    $('#btn_edit_user').click(function() {
                        if ($('#edit_user  #customer').val() != 'none' && $('#edit_user  #user_name').val() != 'none')
                        {
                            get_info_user($('#edit_user  #user_name').val());
                        }
                    });
                    $('#btn_edit_customer').click(function() {
                        if ($('#edit_customer #customer').val() != 'none')
                        {
                            get_edit_customer($('#edit_customer #customer').val());
                        }
                    });
                    $('#btn_LookProfilCustomer').click(function() {
                        if ($('#LookProfilCustomer #customer').val() != 'none')
                        {
                            get_LookProfilCustomer($('#LookProfilCustomer #customer').val());
                        }
                    });


                });
            </script>
    <?php
    }//end session Admin
}
if ($_POST['do'] == 'get_new_form_user') {
    ?>
        <form id="form_new_user" class="admin_form" name="form_new_user" enctype="multipart/form-data" method="post" action="update.php">
            <h3>יצירת משתמש חדש</h3>
            <input id="hid_new_user" name="hid_new_user" type="hidden"  />
                <fieldset>
                <legend></legend>
                <div class="form_set">
                    <label>שם משתמש:</label>
                    <input id="name" name="name" type="text"  />
                </div>
                <div class="form_set">
                    <label>סיסמא:</label>
                    <input id="password" name="password" type="text"  />
                </div>
                <div class="form_set">
                    <label>אימות סיסמא:</label>
                    <input id="password2" name="password2" type="text"  />
                </div>
            </fieldset>
            <fieldset>
                <div class="form_set">
                    <label>לקוח:</label>
                    <select id="customer" name="customer">
                        <option value="none" >לקוח:</option>
    <?php get_customer(); ?>
                    </select>
                </div>
                <div class="form_set">
                    <label>אימייל:</label>
                    <input id="mail" name="mail" type="text"  />
                </div>
                <div class="form_set">
                    <label>תפקיד:</label>
                    <select id="role_type" name="role_type">
    <?php get_role_type(); ?>
                    </select>
                </div>
                <div class="form_set">
                    <label>שם פרטי:</label>
                    <input id="Fname" name="Fname" type="text"  />
                </div>
                <div class="form_set">
                    <label>שם משפחה:</label>
                    <input id="Lname" name="Lname" type="text"  />
                </div>
                <div class="form_set">
                    <label>טלפון:</label>
                    <input id="pon" name="pon" type="text"  />
                </div>
                <div class="form_set">
                    <label>סלולרי:</label>
                    <input id="mobile" name="mobile" type="text"  />
                </div>
            </fieldset>
            <fieldset>
                <div class="form_set">
                    <div id="div_send_mail" class="form_set">
                        <input id="send_mail" name="send_mail" type="checkbox" value="1" checked="checked" />
                        <label>שליחת מייל לכל הודעה חדשה:</label>
                    </div>   
                </div> 
                <div id="YourCompany" class="form_set displayN clearR">
                    <label>עובד חברה</label>
                    <input type="radio" name="Employee-Friilnsr" value="Employee"  />
                    <label>פרילנסר</label>
                    <input type="radio" name="Employee-Friilnsr" value="Friilnsr"  />
                    <label>לינק לתיק עבודות</label>
                    <input name="Portfolio" type="text" />
                </div>     
            </fieldset>
            <input id="btn_form_new_user" name="btn_form_new_user" type="button" value="שלח" />
        </form>
             <div id="test"></div>
        <div id="error" ><li class="red">* עליך למלא את השדות:</li></div>
    </div>
    <script src="inc/js/jquery.validate.js" type="text/javascript"></script>
    <script>
        jQuery.validator.addMethod("selectNone",
                function(value, element) {
                    if (element.value == "none")
                    {
                        return false;
                    }
                    else
                        return true;
                },
                "Please select an option."
                );
        $(document).ready(function(e) {
            $('#customer').change(function(e) {
                if ($('#customer').val() ==<?php echo $IdCompany; ?>)
                {
                    $('#YourCompany').css('display', 'block');
                }
                else
                {
                    $('#YourCompany').css('display', 'none');
                }
            });
            $('#role_type').change(function() {
                if ($('#role_type').val() == 4 || $('#role_type').val() == 1 || $('#role_type').val() == 6)
                {
                    $('#div_send_mail').css('display', 'block');
                }
                else
                {
                    $('#div_send_mail').css('display', 'none');
                }
            });


            $('#form_new_user #customer ').change(function() {

                var temp = $('#form_new_user #customer').val();
                change_new_user(temp);
            });
            $('#btn_form_new_user').click(function(e) {
                $('#hid_isuser').val(0);
                $('#form_new_user').submit();
            });
            $("#form_new_user").validate({
                rules: {
                    name: {required: true},
                    password: {required: true, },
                    password2: {equalTo: "#password"},
                    customer: {selectNone: true},
                    mail: {required: true, email: true},
                    role_type: {selectNone: true},
                    customer_add: {selectNone: true},
                    project: {selectNone: true}
                },
                messages:
                        {
                            name: "שם משתמש",
                            password: "סיסמא",
                            password2: "אימות סיסמא",
                            customer: "לקוח",
                            mail: "אימייל",
                            role_type: "תפקיד",
                            customer_add: "לקוח",
                            project: "פרויקט"
                        },
                errorLabelContainer: '#error',
                errorElement: "li",
                submitHandler: function(form)
                {
                    if ($('#hid_isuser').val() == 1) {
                        if ($('#hid_res').val() == 0) {
                            form.submit();
                        }

                    }
                    else
                    {
                        var x = $('#form_new_user #name').val();
                        isuser(x);
                        $('#hid_isuser').val(1);
                    }
                }
            });
        });
    </script>

    <?php
}

if ($_POST['do'] == 'get_new_form_project') {
    ?> 	
    <form id="form_new_project" class="admin_form" name="form_new_project" enctype="multipart/form-data" method="post" action="update.php" >
        <h3>יצירת פרויקט חדש</h3>
        <input id="hid_new_project" name="hid_new_project" type="hidden"  />
        <fieldset>

            <legend>פרטי פרויקט</legend>	
            <div class="form_set">  
                <label>לקוח:</label>
                <select id="customer" name="customer" >
                    <option value="none" selected="selected">לקוח</option>
    <?php get_customer(); ?>
                </select>
            </div>
            <div class="form_set">
                <label>סוג פרויקט:</label>
                <select id="type" name="type">
                    <option  selected="selected" value="none"> סוג פרויקט</option>
                    <option value="fb">פייסבוק</option>
                    <option value="IT">מערכת מידע</option>
                    <option value="site">אתר</option>
                    <option value="blog">בלוג</option>
                </select>
            </div>
            <div class="form_set">
                <label>שם הפרויקט:</label>
                <input id="name" name="name" type="text"  />
            </div>
            <div class="form_set">
                <label>סטאטוס:</label>
                <select name="SelStatusProject" >
    <?php echo project::GetListStatusProject(); ?>
                </select>

            </div>

            <div class="form_set">
                <label>תחילת פרויקט:</label>
                <input id="start_date" name="start_date" type="text"  />
            </div>
            <div class="form_set">
                <label>סיום הפרויקט:</label>
                <input  id="end_date" name="end_date" type="text" />
            </div>
            <div class="form_set">
                <label>סביבת ייצור:</label>
                <input id="link" name="link" type="text"  />
            </div>
            <div class="form_set">
                <label>סביבת בדיקות:</label>
                <input id="test_link" name="test_link" type="text" />
            </div>
            <div class="form_set">
                <label>בחר קובץ:</label>
                <input id="file_project" name="file_project" type="file" />
            </div>
        </fieldset>
        <fieldset>

            <label>תיאור הפרויקט:</label>
            <textarea id="description" name="description" ></textarea>

            <div class="form_set_price ">
                <label>הצעת מחיר:</label>
                <input name="Quotation" type="text" />
    <?php $today = getdate(); ?>
                <label>תאריך:</label>
                <input name="DateQuotation" id="DateQuotation" value="<?php echo $today['mday'] . '-' . $today['mon'] . '-' . $today['year']; ?>" type="text" />
            </div>
            <div class="form_set_price clearR ">
                <label>מחיר סופי:</label>
                <input name="FinalPrice" type="text" />
                <?php $today = getdate(); ?>
                <label>תאריך:</label>
                <input name="DateFinalPrice" id="DateFinalPrice" value="<?php echo $today['mday'] . '-' . $today['mon'] . '-' . $today['year']; ?>" type="text" />
            </div>
        </fieldset>

        <fieldset>
            <legend>פרטי גישה</legend>
            <table id="edit_access_details">
                <thead>
                <th></th>
                <th>FTP</th>
                <th>DB</th>
                <th>מערכת ניהול</th>
                <th>Cpanel</th>
                </thead>
                <tbody> 
                    <tr>
                        <td class="color_turkiz">כתובות</td>
                        <td><input id="ftp_address" name="ftp_address" type="text"  /></td>
                        <td><input id="db_address" name="db_address" type="text"  /></td>
                        <td><input id="manager_address" name="manager_address" type="text"  /></td>
                        <td><input id="cp_address" name="cp_address" type="text"  /></td>
                    </tr>
                    <tr>
                        <td class="color_turkiz">משתמש</td>
                        <td><input id="ftp_user" name="ftp_user" type="text" /></td>
                        <td><input id="db_user" name="db_user" type="text"  /></td>
                        <td><input id="manager_user" name="manager_user" type="text"  /></td>
                        <td><input id="cp_user" name="cp_user" type="text"  /></td>
                    </tr>
                    <tr>
                        <td class="color_turkiz">סיסמא</td>
                        <td><input id="ftp_pass" name="ftp_pass" type="text"  /></td>
                        <td><input id="db_pass" name="db_pass" type="text"  /></td>
                        <td><input id="manager_pass" name="manager_pass" type="text"  /></td>
                        <td><input id="cp_pass" name="cp_pass" type="text"  /></td>
                    </tr>
                    <tr>
                        <td class="color_turkiz">שם</td>
                        <td></td>
                        <td><input id="db_name" name="db_name" type="text"  /></td>
                        <td> </td>
                        <td> </td>
                    </tr>

                </tbody>
            </table>
            <input type="submit"  value="שלח"/>
        </fieldset>

    <?php
    $user = user::get_user_by_type(2);
    foreach ($user as $U) {
        ?>
                           <option value="<?php echo $U->getuser_id() ?>" ><?php echo $U->user_name; ?></option>    
    <?php }
    ?>
           </select>
           <label>בודקי תוכנה</label>
           <select id="QA" name="QA">
              <option value="none" selected="selected">בודקי תוכנה</option>
        <?php
        $user = user::get_user_by_type(3);
        foreach ($user as $U) {
            ?>
                           <option value="<?php echo $U->getuser_id() ?>" ><?php echo $U->user_name; ?></option>    
        <?php }
        ?>
           </select>
          </fieldset>  -->

    </form><!-- form_new_project-->

    <div id="error" >עליך למלא את כל השדות</div>
    </div>
    <script src="inc/js/jquery.validate.js" type="text/javascript"></script>
    <script>
        jQuery.validator.addMethod("selectNone",
                function(value, element) {
                    if (element.value == "none")
                    {
                        return false;
                    }
                    else
                        return true;
                },
                "Please select an option."
                );
        $(document).ready(function(e) {
            $("#form_new_project").validate({
                rules: {
                    name: {required: true},
                    customer: {selectNone: true},
                    type: {selectNone: true}

                },
                messages:
                        {
                            name: "שם פרויקט",
                            customer: "לקוח",
                            type: "סוג פרויקט",
                        },
                errorLabelContainer: '#error',
                errorElement: "li",
                submitHandler: function(form)
                {
                    var ext = $('#file_project').val().split('.').pop().toLowerCase();

                    var allow = new Array('jpg', 'jpeg', 'png,', 'txt', 'pdf', 'doc', 'docx', 'ppt', 'pptx', 'xlsx', 'xls');//'gif','png', 
                    if (ext == "")
                    {
                        form.submit();
                    }
                    else
                    {
                        if (jQuery.inArray(ext, allow) == -1)
                        {
                            alert("הפורמט של הקובץ צריך להיות :jpeg,txt,pdf,doc,docx,ppt,pptx,xlsx");
                            return false;
                        }
                        else
                        {
                            form.submit();
                        }

                    }
                }

            });
            $(function() {
                var dates = $("#start_date,#end_date ,#DateQuotation,#DateFinalPrice").datepicker({
                    defaultDate: "+1w",
                    changeMonth: true,
                    numberOfMonths: 1,
                    changeYear: true,
                    dayNamesMin: ['א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ש'],
                    isRTL: true,
                    monthNamesShort: ['ינו', 'פבר', 'מרץ', 'אפר', 'מאי', 'יונ', 'יול', 'אוג', 'ספט', 'אוק', 'נוב', 'דצמ'],
                    prevText: '',
                    nextText: '',
                    dateFormat: 'dd-mm-yy',
                    /*onSelect: function( selectedDate ) {
                     var option = this.id == "start_date" ? "minDate" : "maxDate",
                     instance = $( this ).data( "datepicker" ),
                     date = $.datepicker.parseDate(
                     instance.settings.dateFormat ||
                     $.datepicker._defaults.dateFormat,
                     selectedDate, instance.settings );
                     dates.not( this ).datepicker( "option", option, date );
                     }*/
                });
            });
        });
    </script>


<?php
}
if ($_POST['do'] == 'get_new_form_customer') {
    ?>
    <form id="form_new_customer" class="admin_form" name="form_new_customer" method="post" action="update.php">
        <h3>יצירת לקוח חדש</h3>
        <input id="hid_new_customer" name="hid_new_customer" type="hidden"  />
        <fieldset>
            <!--<div class="form_set">
              <label>מס"ד </label>
              <input id="SD" name="SD" type="text" /> 
            </div>-->
            <div class="form_set">
                <label>שם לקוח:</label>
                <input id="name" name="name" type="text" />
            </div>
            <div id="TypeCustomer" class="form_set">
                <label>סוג לקוח:</label>
                <span>עסקי</span>
                <input type="radio" name="status_customer" checked="checked" value="Business"  />
                <span>פרטי</span>
                <input type="radio" name="status_customer" value="Private"  />
            </div>
            <div class="form_set">
                <label>ח.פ/ע.מ:</label>
                <input type="text" name="LTD"  /><!-- רק מספרים-->
            </div>
            <div id="Divpon" class="form_set">
                <label>טלפון משרד:</label>
                <input type="text" name="pon"  />
                <select name="PrefixPon" class="prefix_select">
                    <option value="02">02</option>
                    <option value="03">03</option>
                    <option value="04">04</option>
                    <option value="08">08</option>
                    <option value="09">09</option>
                    <option value="076">076</option>
                    <option value="077">077</option>
                </select>
            </div>
            <div class="form_set">
                <label>פקס:</label>
                <input type="text" name="fax" />
                <select name="PrefixFax" class="prefix_select">
                    <option value="02">02</option>
                    <option value="03">03</option>
                    <option value="04">04</option>
                    <option value="08">08</option>
                    <option value="09">09</option>
                    <option value="076">076</option>
                    <option value="077">077</option>
                </select>
            </div>
            <div class="form_set">
                <label>סטאטוס:</label>
                <select name="status">
                    <option value="1" selected="selected">פוטנציאלי</option>                 
                    <option value="1">פעיל</option>                 
                    <option value="1">לא פעיל</option>                 
                </select>

            </div>
        </fieldset>
        <fieldset>
            <div id="DivAddress" class="form_set form_set_big">
                <label>כתובות:</label>
                <input type="text" name="Address"  />
            </div>
            <div id="DivSite" class="form_set form_set_big">
                <label>אתר אינטרנט:</label>
                <input type="text" name="site"  />
            </div>
            <div class="form_set form_set_big">
                <label>תחום עיסוק:</label>
                <input type="text" name="LineBusiness" />
            </div>
            <div class="form_set form_set_big">
                <label>איך הגיע?</label>
                <input type="text"  name="Arrived" />
            </div>
        </fieldset>
        <fieldset>
            <div class="form_set form_set_select" style=" width:100%; height:auto;">
                <label>הערות:</label>
                <textarea id="description" name="notice"></textarea>
            </div>
        </fieldset>

        <!-- <div class="form_set clearR">
          <a id="AddNewUserOfCustomer" onclick="AddNewUserCustomer($('#form_new_customer #',4)">הוספת איש קשר</a>
           <div id="ContentNewUser"></div>
         </div>-->

    </div>

    </fieldset>
    <input id="btn_new_customer" name="btn_new_customer" type="submit" value="שלח"  />
    </form>

    <div id="error" >עליך למלא את כל השדות</div>
    </div>
    <script src="inc/js/jquery.validate.js" type="text/javascript"></script>
    <script>
        jQuery.validator.addMethod("selectNone",
                function(value, element) {
                    if (element.value == "none")
                    {
                        return false;
                    }
                    else
                        return true;
                },
                "Please select an option."
                );
        $(document).ready(function(e) {
            $("#form_new_customer").validate({
                rules: {
                    name: {required: true},
                    site: {url: true}
                },
                messages:
                        {
                            name: "שם לקוח",
                            site: "כתובת אתר האינטרנט לא חוקית  ",
                        },
                errorLabelContainer: '#error',
                errorElement: "li",
            });
        });
    </script>

<?php
}
if ($_POST['do'] == 'change_edit_project') {
    $id_customer = $_POST['id_customer'];
    $project = new project();
    $temp = project::getallproject_admin();

    echo '<option value="none" selected="selected">פרויקט</option>';

    foreach ($temp as $P) {
        $project->getby_id($P);

        if ($project->project_customer == $id_customer) {
            $id = $project->getid();
            echo "<option value='$id'>$project->project_name</option>";
        }
    }
}

if ($_POST['do'] == 'change_edit_user_add_project') {
    $id_customer = $_POST['id_customer'];
    $project = new project();
    $temp = project::getallproject_admin();

    echo '<option value="none" selected="selected">פרויקט</option>';

    foreach ($temp as $P) {
        $project->getby_id($P);

        if ($project->project_customer == $id_customer) {
            $id = $project->getid();
            echo "<option value='$id'>$project->project_name</option>";
        }
    }
}
if ($_POST['do'] == 'change_edit_user') {
    $id_customer = $_POST['id_customer'];
    $user = new user();
    $temp = user::getby_customer($id_customer);


    echo " <option value='none' selected='selected'>שם משתמש</option>";

    foreach ($temp as $P) {
        $temp_id = $P->getuser_id();
        $temp_name = $P->user_name;
        echo " <option value='$temp_id'>$temp_name</option>";
    }
}

if ($_POST['do'] == 'get_info_project') {
    $id_project = $_POST['id_project'];
    $project = new project();
    $project->getby_id($id_project);
    $access_details = new pad();
    $access_details->getby_id($id_project);
    ?>
    <form id="form_edit_project" class="admin_form" name="form_edit_project" method="post" action="update.php" enctype="multipart/form-data">
        <h3>עריכת פרויקט</h3>
        <input id="hid_edit_project" name="hid_edit_project" type="hidden" value="<?php echo $project->getid(); ?>"  />
        <fieldset>

            <legend>פרטי פרויקט</legend>
            <div class="form_set">
                <label>לקוח:</label>
                <select id="customer" name="customer" >
    <?php get_customer_edit($project->project_customer); ?>
                </select>
            </div>	
            <div class="form_set">
                <label>סוג הפרויקט:</label>
                <select id="type" name="type">
                    <option  value="none"> סוג פרויקט</option>
                    <option value="fb"<?php if ($project->project_type == 'fb') { ?> selected="selected" <?php } ?>>פייסבוק</option>
                    <option value="IT"<?php if ($project->project_type == 'IT') { ?> selected="selected" <?php } ?>>מערכת מידע</option>
                    <option value="site"<?php if ($project->project_type == 'site') { ?> selected="selected" <?php } ?>>אתר</option>
                    <option value="site"<?php if ($project->project_type == 'blog') { ?> selected="selected" <?php } ?>>בלוג</option>
                </select>
            </div>
            <div class="form_set">
                <label>שם הפרויקט:</label>
                <input id="name" name="name" type="text"  value="<?php echo $project->project_name; ?>" />
            </div>
            <div class="form_set">
                <label>סטאטוס:</label> 
                <select id="project_status" name="project_status">
    <?php get_project_status($project->project_status); ?>
                </select>
            </div>
            <div class="form_set">
                <label>תחילת פרויקט:</label>
                <input id="start_date" name="start_date" type="text" value="<?php echo project::ReverseDate($project->project_start_date); ?>" />
            </div>
            <div class="form_set">
                <label>סיום הפרויקט:</label>
                <input  id="end_date" name="end_date" type="text" value="<?php echo project::ReverseDate($project->project_end_date); ?>" />
            </div>

            <div class="form_set">
                <label>סביבת ייצור:</label>
                <input id="link" name="link" type="text" value="<?php echo $project->project_link; ?>"/>
            </div>
            <div class="form_set">
                <label>סביבת בדיקות:</label></td>
                <input id="test_link" name="test_link" type="text" value="<?php echo $project->project_test_link; ?>"/></td>
            </div>
            <div class="form_set">    
                <label>פעיל:</label>
                <input class="is_project_active" id="active" name="active" type="checkbox" value="1" 
    <?php if ($project->project_active == 1) { ?> checked="checked"<?php } ?>  />
            </div>
        </fieldset>

        <fieldset>
            <div id="Canceled"  <?php if ($project->project_status != 5) { ?>class="displayN" <?php } ?> style="width:100%; float:right;" >
                <label>סיבת הביטול</label>
                <select id="SelCanceled" name="SelCanceled" >
    <?php echo $project->GetListCanceledOfProject(); ?>
                </select>
    <?php $cancel = explode(',', $project->Canceled); ?>
                <textarea name="TextCanceled"><?php echo $cancel[1]; ?></textarea>
            </div>
        </fieldset>

        <fieldset>
            <div  id="AllFileProject">
                <label>קבצי הפרויקט: </label>
    <?php
    $arrfile = explode(',', $project->attachments);
    foreach ($arrfile as $SingleAttachments) {
        ?> 
                    <div style="float:right; clear:both;">
                        <a id="watchProjectFile" target="_blank" href="<?php echo $SingleAttachments ?>">צפייה בקובץ</a>
                        <input id="file_project_edit" name="file_project_edit" type="text" value="<?php echo $SingleAttachments ?>" />
                        <label style="float:right;margin-right:15px;">החלפת קובץ:</label>
                        <input id="file_project_edit_upload" name="file_project_edit_upload[]" type="file"  readonly="readonly" />
                    </div>
    <?php } ?>
                <div style="clear:both; float:right;" id="UploadFile"><span>הוספת קובץ </span>
                </div>
            </div>
        </fieldset>
        <fieldset>
            <label>תיאור הפרויקט:</label>
            <textarea id="description"  name="description" ><?php echo $project->project_description; ?></textarea>
        </fieldset>
        <fieldset>
            <div class="form_set_price ">
                <label>הצעת מחיר:</label>
                <input name="Quotation" type="text" value="<?php echo $project->Quotation; ?>" />
    <?php $today = getdate(); ?>
                <label>תאריך:</label>
                <input name="DateQuotation" id="DateQuotation" value="<?php echo project::ReverseDate($project->DateQuotation); ?>"
                       class="" type="text" />
            </div>
            <div class="form_set_price ">
                <label>מחיר סופי:</label>
                <input name="FinalPrice" type="text" value="<?php echo $project->FinalPrice; ?>" />
    <?php $today = getdate(); ?>
                <label>תאריך:</label>
                <input name="DateFinalPrice" id="DateFinalPrice" value="<?php echo project::ReverseDate($project->DateFinalPrice); ?>"
                       class="" type="text"/>
            </div>
        </fieldset>

        <style>
            #cart h1{ float:right; width:100%; text-align:center;}
            #cart { margin-top:15px; float:right; width:45%; height:auto; }
            #products { margin-top:15px; float:left; width:48%; height:auto;}
            /* style the list to maximize the droppable hitarea */
            #cart ol, #products ul, #products ol{ float:right; width:100%; border:1px solid #666; margin:0;}
            #cart ul{float:right; width:100%; border:solid #666; border-width:1px 1px 0 1px;}
            #cart li{text-align:center;}
            #cart ul li{ border:none;}
            #cart li, #products li { float:right; width:100%; border-bottom:1px solid #609395;}
            #products li{cursor:move;}
            #cart .ui-droppable{min-height:50px;}
            #EditContact{float:right;}
        </style>

        <div id="cart" class="">
            <h1 class="ui-widget-header">שיוך לפרוייקט</h1>
            <ul >
    <?php
    $perm = permissions::GetPermissionsOfProject($project->getid());

    if ($perm != 0) {
        foreach ($perm as $singleuser) {
            ?>
                        <li class="placeholder color_turkiz" id="<?php echo $singleuser->getuser_id() ?>" ><?php echo $singleuser->user_name . '-' . user::GetNameOfRoletype($singleuser->role_type); ?><span id="delete" onclick="Delete(<?php echo $singleuser->getuser_id() ?>,<?php echo $project->getid() ?>)" >*</span></li>

        <?php }
    } ?> 
                <!-- <?php
                $perm = user::get_user_contects($project->project_customer);

                if ($perm != 0) {
                    foreach ($perm as $singleuser) {
                        ?>
                                    <li class="placeholder color_turkiz" id="<?php echo $singleuser->getuser_id() ?>" ><?php echo $singleuser->user_name . '-' . user::GetNameOfRoletype($singleuser->role_type); ?><span id="delete" onclick="Delete(<?php echo $singleuser->getuser_id() ?>,<?php echo $project->getid() ?>)" >*</span></li>
                                 
        <?php }
    } ?> -->
            </ul>
            <div class="ui-widget-content">
                <ol>
                    <li class="placeholder"> גרור משתמשים לשיוך</li>
                </ol>
            </div>
        </div>
        <div id="products">
            <h1 style="float:right; width:100%; text-align:center;" class="ui-widget-header">אנשי קשר</h1>
            <div id="catalog">


                <ul>
    <?php
    $users = user::getby_customer($project->project_customer);
    foreach ($users as $singleuser) {
        if ($singleuser->role_type == 5) {
            ?>
                            <li style="z-index:1002" value="<?php echo $singleuser->getuser_id() ?>" class="color_turkiz" ><?php echo $singleuser->user_name ?>-איש קשר</li>
        <?php }
    } ?>





                    <?php
                    $users = user::getby_customer(8);

                    foreach ($users as $singleuser) {
                        if ($singleuser->role_type == 2) {
                            ?>
                            <li style="z-index:1002" value="<?php echo $singleuser->getuser_id() ?>"  class="color_turkiz" ><?php echo $singleuser->user_name ?>-עובד חברה</li>
        <?php }
    } ?>


                    <?php
                    $users = user::getby_customer(8);

                    foreach ($users as $singleuser) {
                        if ($singleuser->role_type == 3) {
                            ?>
                            <li style="z-index:1002" value="<?php echo $singleuser->getuser_id() ?>"  class="color_turkiz" ><?php echo $singleuser->user_name ?>-בודק מוצר</li>
                        <?php }
                    } ?>
                    <?php
                    $users = user::getby_customer(8);

                    foreach ($users as $singleuser) {
                        if ($singleuser->role_type == 6) {
                            ?>
                            <li style="z-index:1002" value="<?php echo $singleuser->getuser_id() ?>"  class="color_turkiz" ><?php echo $singleuser->user_name ?>-איש שיווק ומכירות</li>
                        <?php }
                    } ?>
                </ul>

            </div>
            <a id="CreateNewUserOfCompany" style="width:150px; float:left;">יצירת איש קשר חדש</a>
        </div>

    </fieldset>        	
    <fieldset>
        <legend>פרטי גישה</legend>
        <table id="edit_access_details">
            <thead>
            <th></th>
            <th>FTP</th>
            <th>DB</th>
            <th>מערכת ניהול</th>
            <th>Cpanel</th>
            </thead>
            <tbody> 
                <tr>
                    <td class="color_turkiz">כתובות</td>
                    <td><input id="ftp_address" name="ftp_address" type="text" 
                               value="<?php echo $access_details->ftp_address ?>" /></td>
                    <td><input id="db_address" name="db_address" type="text" 
                               value="<?php echo $access_details->db_address ?>" /></td>
                    <td> <input id="manager_address" name="manager_address" type="text"
                                value="<?php echo $access_details->manager_address ?>" /></td>
                    <td><input id="cp_address" name="cp_address" type="text" 
                               value="<?php echo $access_details->cp_address ?>" /></td>
                </tr>
                <tr>
                    <td class="color_turkiz">משתמש</td>
                    <td><input id="ftp_user" name="ftp_user" type="text"
                               value="<?php echo $access_details->ftp_user; ?>" /></td>
                    <td><input id="db_user" name="db_user" type="text" 
                               value="<?php echo $access_details->db_user ?>" /></td>
                    <td><input id="manager_user" name="manager_user" type="text"
                               value="<?php echo $access_details->manager_user ?>"/></td>
                    <td><input id="cp_user" name="cp_user" type="text"
                               value="<?php echo $access_details->cp_user ?>" /></td>
                </tr>
                <tr>
                    <td class="color_turkiz">סיסמא</td>
                    <td> <input id="ftp_pass" name="ftp_pass" type="text"
                                value="<?php echo $access_details->ftp_pass; ?>"  /></td>
                    <td> <input id="db_pass" name="db_pass" type="text"
                                value="<?php echo $access_details->db_pass ?>" /></td>
                    <td><input id="manager_pass" name="manager_pass" type="text"
                               value="<?php echo $access_details->manager_pass ?>"/></td>
                    <td> <input id="cp_pass" name="cp_pass" type="text" 
                                value="<?php echo $access_details->cp_pass ?>" /></td>
                </tr>
                <tr>
                    <td class="color_turkiz">שם</td>
                    <td></td>
                    <td> <input id="db_name" name="db_name" type="text" 
                                value="<?php echo $access_details->db_name ?>" /></td>
                    <td> </td>
                    <td> </td>
                </tr>

            </tbody>
        </table>

        <input type="submit"  value="עדכן"/>
    </fieldset>
    </form>      
    <div id="test"></div>
    <div id="error" >עליך למלא את כל השדות</div>
    </div>
    <script src="inc/js/jquery.validate.js" type="text/javascript"></script>
    <script>
        jQuery.validator.addMethod("selectNone",
                function(value, element) {
                    if (element.value == "none")
                    {
                        return false;
                    }
                    else
                        return true;
                },
                "Please select an option."
                );

        $(document).ready(function(e) {
            $('#CreateNewUserOfCompany').click(function(e) {
                CreateNewUserOfProject($('#customer').val());
            });
            $('#UploadFile span').click(function(e) {

                $('#UploadFile').append(' <input id="file_project_edit_upload" name="file_project_edit_upload_new[]" type="file" class="file_project_edit_upload_new" />');
            });
            $('#project_status').change(function(e) {
                if ($('#project_status').val() == 5)
                {
                    $('#Canceled').css('display', 'block');
                }
                else
                {
                    $('#Canceled').css('display', 'none');
                }
            });
            $(function() {
                var dates = $("#start_date,#end_date,#DateQuotation,#DateFinalPrice").datepicker({
                    defaultDate: "+1w",
                    changeMonth: true,
                    numberOfMonths: 1,
                    changeYear: true,
                    dayNamesMin: ['א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ש'],
                    isRTL: true,
                    monthNamesShort: ['ינו', 'פבר', 'מרץ', 'אפר', 'מאי', 'יונ', 'יול', 'אוג', 'ספט', 'אוק', 'נוב', 'דצמ'],
                    prevText: '',
                    nextText: '',
                    dateFormat: 'dd-mm-yy',
                    /*onSelect: function( selectedDate ) {
                     var option = this.id == "start_date" ? "minDate" : "maxDate",
                     instance = $( this ).data( "datepicker" ),
                     date = $.datepicker.parseDate(
                     instance.settings.dateFormat ||
                     $.datepicker._defaults.dateFormat,
                     selectedDate, instance.settings );
                     dates.not( this ).datepicker( "option", option, date );
                     }*/
                });
            });
            $("#form_edit_project").validate({
                rules: {
                    name: {required: true},
                    customer: {selectNone: true},
                    type: {selectNone: true}

                },
                messages:
                        {
                            name: "שם פרויקט",
                            customer: "לקוח",
                            type: "סוג פרויקט",
                        },
                errorLabelContainer: '#error',
                errorElement: "li",
                submitHandler: function(form)
                {
                    var ext = $('#file_project_edit_upload').val().split('.').pop().toLowerCase();

                    var allow = new Array('jpg', 'jpeg', 'png', 'txt', 'pdf', 'doc', 'docx', 'ppt', 'pptx', 'xlsx', 'xls');//'gif','png', 
                    var bool = true;
                    if (jQuery.inArray(ext, allow) == -1 && ext != "")
                    {
                        alert("הפורמט של הקובץ צריך להיות :jpeg,txt,pdf,doc,docx,ppt,pptx,xlsx");
                        return false;
                        bool = false;
                    }
                    else
                    {
                        if (bool) {
                            form.submit();
                        }
                    }



                }

            });



        });
    </script>

    <?php
}
if ($_POST['do'] == 'get_info_user') {
    $id_user = $_POST['id_user'];
    $temp_user = new user();
    $temp_user->getby_id($id_user);
    ?>
    <form id="form_edit_user" class="admin_form" name="form_edit_user" method="post" action="update.php">
        <h3>עריכת משתמש </h3>
        <input id="hid_edit_user" name="hid_edit_user" type="hidden"  value="<?php echo $id_user; ?>" />
        <fieldset>
            <legend>פרטי משתמש</legend>
            <div class="form_set">
                <label>שם משתמש:</label>
                <input id="name" name="name" type="text" value="<?php echo $temp_user->user_name ?>" />
            </div>
            <div class="form_set">
                <label>סיסמא:</label>
                <input id="password" name="password" type="text" value="<?php echo $temp_user->user_password ?>" />
            </div>
            <div class="form_set">
                <label>אימות סיסמא:</label>
                <input id="password2" name="password2" type="text" value="<?php echo $temp_user->user_password ?>" />
            </div>
            <div class="form_set">
                <label>לקוח:</label>
                <select id="customer" name="customer">
    <?php get_customer_edit($temp_user->user_customer); ?>
                </select>
            </div>
            <div class="form_set">
                <label>אימייל:</label>
                <input id="mail" name="mail" type="text" value="<?php echo $temp_user->user_mail ?>" />
            </div>
            <div class="form_set">
                <label>תפקיד:</label>                
                <select id="role_type" name="role_type" class="send_mail">
    <?php get_role_type_edit($temp_user->role_type); ?>
                </select>
            </div>
            <div class="form_set">
                <label>שם פרטי:</label>
                <input id="Fname" name="Fname" type="text" value="<?php echo $temp_user->Fname; ?>" />
            </div>
            <div class="form_set">
                <label>שם משפחה:</label>
                <input id="Lname" name="Lname" type="text" value="<?php echo $temp_user->Lname; ?>" />
            </div>
            <div class="form_set">
                <label>טלפון:</label>
                <input id="pon" name="pon" type="text" value="<?php echo $temp_user->pon; ?>" />
            </div>
            <div class="form_set">
                <label>סלולרי:</label>
                <input id="mobile" name="mobile" type="text" value="<?php echo $temp_user->mobile; ?>" />
            </div>
        </fieldset>
        <fieldset>
            <div id="div_send_mail" class="form_set" >
                <input id="send_mail" name="send_mail"  type="checkbox" value="1"
    <?php if ($temp_user->send_mail == 1) { ?> checked="checked"<?php } ?> />
                <label>שליחת מייל לכל הודעה חדשה</label>
            </div> 
            <div class="form_set">
                <label>משתמש פעיל:</label>
                <input id="user_active" name="user_active" type="checkbox" value="1" 
    <?php if ($temp_user->user_active == 1) { ?> checked="checked"<?php } ?> />
            </div> 
        </fieldset>
        <fieldset>
            <div id="YourCompany" <?php if ($temp_user->user_customer == $IdCompany) { ?>class="form_set clearR " <?php } else { ?>class="form_set displayN clearR"<?php } ?>>  
                <label>עובד חברה</label>
                <input type="radio" name="Employee-Friilnsr" value="Employee" 
    <?php if ($temp_user->Employee_Friilnsr == 'Employee') { ?> checked="checked" <?php } ?> />
                <label>פרילנסר</label>
                <input type="radio" name="Employee-Friilnsr" value="Friilnsr"  
                       <?php if ($temp_user->Employee_Friilnsr == 'Friilnsr') { ?> checked="checked" <?php } ?> />
                <label>לינק לתיק עבודות</label>
                <input name="Portfolio" type="text" value="<?php echo $temp_user->Portfolio; ?>"/>
            </div>     
        </fieldset>
        <fieldset id="add_customer">
            <legend>שייוך לפרויקטים</legend>
            <div class="form_set">
                <label>לקוח:</label>
                <select id="add_customers" name="add_customers">
                    <option value="none" selected="selected">לקוח</option>
    <?php get_customer(); ?>
                </select>
            </div>
            <div class="form_set">
                <label>פרויקט:</label>
                <select id="project" name="project" >
                    <option>פרויקט</option>
                </select>
            </div>
            <span id="er" ></span>
            <div class="form_set">
                <a id="add_permissions" class="info_link"> הוסף הרשאה </a>
            </div>
            <!-- <input id="btn_add_customer" name="btn_add_customer" type="button" value="+"  />-->
        </fieldset>
        <fieldset id="add_customer">
            <legend>פרויקטים משוייכים למשתמש</legend>
            <div id="Adminedit_user"></div>
            <script> getAdmin('edit_user', $('#edit_user #user_name').val());</script>
        </fieldset>
        <input id="btn_form_edit_user" name="btn_form_edit_user" type="submit" value="עדכן" />
    </form>

    <div id="error" >עליך למלא את כל השדות</div>
    </div>
    <script src="inc/js/jquery.validate.js" type="text/javascript"></script>
    <script>
        jQuery.validator.addMethod("selectNone",
                function(value, element) {
                    if (element.value == "none")
                    {
                        return false;
                    }
                    else
                        return true;
                },
                "Please select an option."
                );

    </script> 
    <script>
        $(document).ready(function(e) {
            $('#customer').change(function(e) {
                if ($('#customer').val() ==<?php echo $IdCompany; ?>)
                {
                    $('#YourCompany').css('display', 'block');
                }
                else
                {
                    $('#YourCompany').css('display', 'none');
                }
            });
            if ($('.send_mail').val() == 4 || $('.send_mail').val() == 1)
            {
                $('#form_edit_user #div_send_mail').css('display', 'block');
            }
            $('.send_mail').change(function() {

                if ($('.send_mail').val() == 4 || $('.send_mail').val() == 1)
                {
                    $('#form_edit_user #div_send_mail').css('display', 'block');
                }
                else
                {
                    $('#form_edit_user #div_send_mail').css('display', 'none');
                }
            });
            $("#form_edit_user #add_customers").change(function() {
                var temp = $('#form_edit_user #add_customers').val();

                change_edit_user_add_project(temp);
            });
            $('#add_permissions').click(function(e) {
                if ($('#form_edit_user #project').val() != 'none')
                {
                    var x = confirm('בטוח שאתה רוצה לתת גישה למשתמש');
                    if (x)
                    {
                        add_permissions($('#form_edit_user #project').val(),
                                $('#form_edit_user #hid_edit_user').val()
                                );
                    }
                }
            });


            $("#form_edit_user").validate({
                rules: {
                    name: {required: true},
                    // password: {required:true,},
                    // password2: {equalTo:"#password"},
                    customer: {selectNone: true},
                    mail: {required: true, email: true},
                    role_type: {selectNone: true}

                },
                messages:
                        {
                            name: "שם משתמש",
                            // password:"סיסמא",
                            customer: "לקוח",
                            mail: "אימייל",
                            role_type: "תפקיד"

                        },
                errorLabelContainer: '#error',
                errorElement: "li",
            });
        });
    </script>
    <?php
}
if ($_POST['do'] == 'get_edit_customer') {
    $id_customer = $_POST['id_customer'];
    /* $st=sprintf("SELECT * FROM `customer` WHERE `Id`=$id_customer");
      $query=mysql_query($st)or die(mysql_error().' '.$st);
      $row=mysql_fetch_assoc($query);
     */

    $customer = new customer();
    $customer->GetById($id_customer);
    ?>
    <form id="form_edit_customer" class="admin_form" name="form_edit_customer" method="post" action="update.php">
        <h3>עריכת לקוח </h3>
        <input id="hid_edit_customer" name="hid_edit_customer" type="hidden" value="<?php echo $id_customer ?>" />
        <fieldset>
            <div class="form_set">
                <label>מס"ד:</label>
                <input id="SD" name="SD" type="text" readonly="readonly" value="<?php echo $customer->Id; ?>"/> 
            </div>
            <div class="form_set">
                <label>שם לקוח:</label>
                <input id="name" name="name" type="text" value="<?php echo $customer->customer_name; ?>" />
            </div>
            <div id="TypeCustomer" class="form_set">
                <label>סוג לקוח:</label>
                <span>עסקי</span>
                <input type="radio" name="status_customer" <?php if ($customer->TypeCustomer == 'Business') { ?> checked="checked"<?php } ?> value="Business"  />
                <span>פרטי</span>
                <input type="radio" name="status_customer" <?php if ($customer->TypeCustomer == 'Private') { ?> checked="checked"<?php } ?>  value="Private"  />
            </div>
            <div class="form_set">
                <label>ח.פ/ע.מ:</label>
                <input type="text" name="LTD" value="<?php echo $customer->LTD; ?>"  /><!-- רק מספרים-->
            </div>
            <div id="Divpon" class="form_set">
                <label>טלפון משרד:</label>
    <?php $pon = explode('-', $customer->Pon); ?>
                <input type="text" name="pon"  value="<?php echo $pon[1]; ?>"  />
                <select name="PrefixPon" class="prefix_select">
                    <option <?php if ($pon[0] == '02') { ?> selected="selected" <?php } ?>   value="02">02</option>
                    <option <?php if ($pon[0] == '03') { ?> selected="selected" <?php } ?> value="03">03</option>
                    <option <?php if ($pon[0] == '04') { ?> selected="selected" <?php } ?> value="04">04</option>
                    <option <?php if ($pon[0] == '08') { ?> selected="selected" <?php } ?>value="08">08</option>
                    <option <?php if ($pon[0] == '09') { ?> selected="selected" <?php } ?> value="09">09</option>
                    <option <?php if ($pon[0] == '076') { ?> selected="selected" <?php } ?> value="076">076</option>
                    <option <?php if ($pon[0] == '077') { ?> selected="selected" <?php } ?> value="077">077</option>
                </select>
            </div>
            <div class="form_set">
                <label>פקס:</label>
    <?php $fax = explode('-', $customer->Fax); ?>
                <input type="text" name="fax" value="<?php echo $fax[1]; ?>" />
                <select name="PrefixFax" class="prefix_select">
                    <option <?php if ($fax[0] == '02') { ?> selected="selected" <?php } ?>  value="02">02</option>
                    <option <?php if ($fax[0] == '03') { ?> selected="selected" <?php } ?> value="03">03</option>
                    <option <?php if ($fax[0] == '04') { ?> selected="selected" <?php } ?> value="04">04</option>
                    <option <?php if ($fax[0] == '08') { ?> selected="selected" <?php } ?> value="08">08</option>
                    <option <?php if ($fax[0] == '09') { ?> selected="selected" <?php } ?> value="09">09</option>
                    <option <?php if ($fax[0] == '076') { ?> selected="selected" <?php } ?> value="076">076</option>
                    <option <?php if ($fax[0] == '077') { ?> selected="selected" <?php } ?> value="077">077</option>
                </select>
            </div>
            <div class="form_set clearR">
                <label>סטאטוס:</label>
                <select name="status">
                    <option <?php if ($customer->Status == 1) { ?>selected="selected" <?php } ?> value="1" >פוטנציאלי</option>                 
                    <option <?php if ($customer->Status == 2) { ?>selected="selected" <?php } ?> value="2">פעיל</option>                 
                    <option <?php if ($customer->Status == 3) { ?>selected="selected" <?php } ?> value="3">לא פעיל</option>                 
                </select>

            </div>
        </fieldset>
        <fieldset>
            <div id="DivAddress" class="form_set form_set_big">
                <label>כתובות:</label>
                <input type="text" name="Address"  value="<?php echo $customer->Address; ?>" />
            </div>
            <div id="DivSite" class="form_set form_set_big">
                <label>אתר אינטרנט:</label>
                <input type="text" name="site" value="<?php echo $customer->Site; ?>"/>
            </div>
            <div class="form_set form_set_big">
                <label>תחום עיסוק:</label>
                <input type="text" name="LineBusiness" value="<?php echo $customer->LineBusiness; ?>" />
            </div>
            <div class="form_set form_set_big">
                <label>איך הגיע?</label>
                <input type="text"  name="Arrived" value="<?php echo $customer->Arrived; ?>" />
            </div>
        </fieldset>
        <fieldset>
            <div class="form_set" style="width:100%; height:auto;">
                <label>הערות:</label>
                <textarea id="description" name="notice"><?php echo $customer->notice; ?></textarea>
            </div>
        </fieldset>

        <fieldset>            
            <style>
                #cart h1{ float:right; width:100%; text-align:center;}
                #cart { margin-top:15px; float:right; width:100%; height:auto; }
                #products { margin-top:15px; float:left; width:48%; height:auto; display:none; }
                /* style the list to maximize the droppable hitarea */
                #cart ol, #products ul, #products ol{ float:right; width:100%; border:1px solid #666; margin:0;}
                #cart ul{float:right; width:100%; border:solid #666; border-width:1px 1px 0 1px;}
                #cart ul li{ border:none;}
                #cart li, #products li { float:right; width:100%; border-bottom:1px solid #609395;}
                #products li{cursor:move;}
                #cart .ui-droppable{min-height:50px;}
                #EditContact{float:right;}
            </style>

            <div id="cart" class="form_set clearR">
                <h1 class="ui-widget-header">משיוכים לפרוייקט</h1>
                <div id="user_contact">
                    <ul>
    <?php
    $users = user::get_user_contects($customer->Id);
    if ($users != 0) {
        foreach ($users as $singleuser) {
            ?>
                                <li class="color_turkiz"><?php echo $singleuser->user_name; ?></li>    
                            <?php }
                        }
                        ?>
                    </ul> 
                </div>
                <div class="ui-widget-content">
                    <ol>
                        <li class="placeholder displayN color_turkiz">גרור משתמשים לשיייוך</li>
                    </ol>
                </div>
            </div>

            <div id="products" class="form_set">
                <h1 class="ui-widget-header">אנשי קשר</h1>

                <div id="catalog">
                    <div >
                        <ul  >
    <?php
    $users = user::getby_customer_in_role_type($customer->Id, 5);

    foreach ($users as $singleuser) {
        ?>
                                <li class="color_turkiz" style="z-index:1002" value="<?php echo $singleuser->getuser_id() ?>" ><?php echo $singleuser->user_name ?></li>
                            <?php } ?>
                        </ul>
                        <a id="CreateNewUserOfCompany" class="color_turkiz" style="width:130px; margin-left:0px;">יצירת איש קשר חדש</a>	
                    </div>

                </div>

            </div>

            <div id="EditContact" class="form_set">ערוך</div>          
            </div>
        </fieldset>
        <fieldset>         
            <div class="form_set">
                <label>לקוח פעיל:</label>
                <input id="customer_active" name="customer_active" type="checkbox" <?php if ($customer->Active == 1) { ?> checked="checked" <?php } ?> value="1"  />
            </div>
        </fieldset>
        <input id="btn_edit_customer" name="btn_edit_customer" type="submit" value="עדכן"  />
    </form> 
    <div id="test"></div>
    <div id="error" >עליך למלא את כל השדות</div>
    </div>
    <script src="inc/js/jquery.validate.js" type="text/javascript"></script>
    <script>
        jQuery.validator.addMethod("selectNone",
                function(value, element) {
                    if (element.value == "none")
                    {
                        return false;
                    }
                    else
                        return true;
                },
                "Please select an option."
                );
        $(document).ready(function(e) {
            $('#CreateNewUserOfCompany').click(function(e) {
                CreateNewUserOfCompany($('#SD').val());
            });
            $('#EditContact').click(function(e) {
                $('#products').show();
                $('#cart').width('50%');
                $('.ui-widget-content li').show();
                $('#EditContact').hide();
            });
            $("#form_edit_customer").validate({
                rules: {
                    name: {required: true}

                },
                messages:
                        {
                            name: "שם לקוח",
                        },
                errorLabelContainer: '#error',
                errorElement: "li",
            });
        });
    </script>
    <?php
}

function get_customer() {
    $st = sprintf("SELECT * FROM `customer` ORDER BY Id ASC");
    $query = mysql_query($st) or die(mysql_error() . ' ' . $st);
    while ($row = mysql_fetch_assoc($query)) {
        $cid = $row['Id'];
        $cname = $row['customer_name'];

        echo "<option value='$cid'>$cname</option>";
    }
}

function get_role_type() {
    $st = sprintf("SELECT * FROM `role_type`");
    $query = mysql_query($st) or die(mysql_error() . ' ' . $st);
    ?>
    <option value="none">תפקיד</option>
    <?php
    while ($row = mysql_fetch_assoc($query)) {
        ?>
        <option value="<?php echo $row['role_type_id']; ?>"><?php echo $row['role_type_desc'] ?></option>			  
    <?php
    }
}

function get_role_type_edit($id_type) {
    $st = sprintf("SELECT * FROM `role_type`");
    $query = mysql_query($st) or die(mysql_error() . ' ' . $st);

    echo "<option value='none'>תפקיד</option>";

    while ($row = mysql_fetch_assoc($query)) {
        $typeid = $row['role_type_id'];
        $typedesc = $row['role_type_desc'];
        if ($typeid == $id_type) {
            echo "<option value='$typeid' selected='selected'>$typedesc</option>";
        } else {
            echo "<option value='$typeid'>$typedesc</option>";
        }
    }
}

if ($_POST['do'] == 'Adminedit_user') {
    $id = $_POST['id'];
    $st = sprintf("SELECT * FROM `permissions` WHERE `user_id`=$id");
    $query = mysql_query($st) or die(mysql_error() . ' ' . $st);
    ?>
    <table border="1px">
        <thead>

        <th>שם משתמש</th>
        <th>שם פרויקט</th>
        <th>פעיל</th>
    </thead>
    <tbody>
    <?php while ($row = mysql_fetch_assoc($query)) {
        ?>
            <tr>
                <td><?php echo user::get_name($row['user_id']); ?></td>
                <td><?php echo project::get_name($row['project_id']); ?></td>
                <td><input id="<?php echo $row['permissions_id']; ?>" name="<?php echo $row['permissions_id']; ?>"
                           type="checkbox" value="1" <?php if ($row['Active'] == 1) { ?> checked="checked" <?php } ?>
                           onclick="active(<?php echo $row['permissions_id']; ?>,<?php echo $row['Active'] ?>)" />
                </td>
            </tr>
        <?php } ?>
    </tbody>

    </table>
    <script>
           function  active(id, active)
           {
               x = Math.abs((active - 1));

               var ans = confirm(' בטוח שאתה  רוצה להחליף סטאטוס פעיל \  ');

               if (ans) {
                   changeActive('permissions', 'permissions_id', id, x);
               }
               else
               {
                   if (active == 1)
                       $('#' + id).attr('checked', 'checked');
                   else
                       $('#' + id).removeAttr('checked', 'checked');

               }
           }
    </script> 
    <?php
}
if ($_POST['do'] == "changeActive") {
    $nameTable = mysql_real_escape_string($_POST['nameTable']);
    $id = mysql_real_escape_string($_POST['id']);
    $active = $_POST['active'];
    $NameId = mysql_real_escape_string($_POST['NameId']);

    $stringChange = sprintf("UPDATE `$nameTable` SET `Active`=$active WHERE `$NameId`=$id ");
    $queryChange = mysql_query($stringChange) or die(mysql_error() . ' ' . $stringChange);
    echo $stringChange;
}
if ($_POST['do'] == 'add_permissions') {

    $id_project = $_POST['id_project'];
    $user_id = $_POST['user_id'];
    $permissions = new permissions();
    $user = new user();
    $user->getby_id($user_id);
    $bool = permissions::is_permissions($user_id, $id_project);

    if ($bool == 0) {
        $permissions->user_id = $user->getuser_id();
        $permissions->project_id = $id_project;
        $permissions->role_type = $user->role_type;
        $permissions->insert();

        echo '';
    } else {
        echo 'הפרוייקט כבר משוייך למשתמש';
    }
}
if ($_POST['do'] == 'AddNewUserCustomer') {
    echo user::GetFormNewUser($_POST['id_custimer'], $_POST['role_type']);
}

function get_customer_edit($id_customer) {
    $st = sprintf("SELECT * FROM `customer`");
    $query = mysql_query($st) or die(mysql_error() . ' ' . $st);
    echo '<option value="none" >לקוח</option>';
    while ($row = mysql_fetch_assoc($query)) {
        $cid = $row['Id'];
        $cname = $row['customer_name'];
        if ($cid == $id_customer) {
            echo "<option value='$cid' selected='selected'>$cname</option>";
        } else {
            echo "<option value='$cid'>$cname</option>";
        }
    }
}

if ($_POST['do'] == 'get_LookProfilCustomer') {
    $id_customer = new customer();
    $id_customer->GetById($_POST['id_customer']);
    $id_customer->LookProfilCustomer();
}
if ($_POST['do'] == 'CreateNewUserOfCompany') {
    $IDCustomer = $_POST['id_custimer'];
    ?>
    <form id="form_new_user" class="admin_form" name="form_new_user" method="post" action="update.php">
        <h3>יצירת משתמש חדש</h3>
        <input id="hid_new_user" name="hid_new_user" type="hidden"  />
        <fieldset>
            <legend>פרטי משתמש:</legend>
            <div class="form_set">
                <label>שם משתמש:</label>
                <input id="name" name="name" type="text"  />
            </div>
            <div class="form_set">
                <label>סיסמא:</label>
                <input id="password" name="password" type="text"  />
            </div>
            <div class="form_set">
                <label>אימות סיסמא:</label>
                <input id="password2" name="password2" type="text"  />
            </div>
        </fieldset>
        <fieldset>
            <div class="form_set">
                <label>לקוח:</label>
                <select id="customer" name="customer">
                    <option value="<?php echo $IDCustomer; ?>"><?php echo customer::GetNameCustomer($IDCustomer); ?></option>
                </select>
            </div>
            <div class="form_set">
                <label>אימייל:</label>
                <input id="mail" name="mail" type="text"  />
            </div>
            <div class="form_set">
                <label>תפקיד:</label>
                <select id="role_type" name="role_type">
                    <option value="4">איש קשר חברה</option>
                </select>
            </div>
            <div class="form_set">
                <label>שם פרטי:</label>
                <input id="Fname" name="Fname" type="text"  />
            </div>
            <div class="form_set">
                <label>שם משפחה:</label>
                <input id="Lname" name="Lname" type="text"  />
            </div>
            <div class="form_set">
                <label>טלפון:</label>
                <input id="pon" name="pon" type="text"  />
            </div>
            <div class="form_set">
                <label>סלולרי:</label>
                <input id="mobile" name="mobile" type="text"  />
            </div>
            <div class="form_set">
                <div id="div_send_mail">
                    <label>שליחת מייל לכל הודעה חדשה:</label>
                    <input id="send_mail" name="send_mail" type="checkbox" value="1" checked="checked" />
                </div>   
            </div> 
            <div id="YourCompany" class="form_set displayN clearR">
                <label>עובד חברה</label>
                <input type="radio" name="Employee-Friilnsr" value="Employee"  />
                <label>פרילנסר</label>
                <input type="radio" name="Employee-Friilnsr" value="Friilnsr"  />
                <label>לינק לתיק עבודות</label>
                <input name="Portfolio" type="text" />
            </div>     
        </fieldset>


        <input id="btn_form_new_user" name="btn_form_new_user" type="button" value="שלח" />
    </form>

    <div id="error" ><li class="red">* עליך למלא את השדות:</li></div>
    </div>
    <script src="inc/js/jquery.validate.js" type="text/javascript"></script>
    <script>
        jQuery.validator.addMethod("selectNone",
                function(value, element) {
                    if (element.value == "none")
                    {
                        return false;
                    }
                    else
                        return true;
                },
                "Please select an option."
                );
        $(document).ready(function(e) {
            $('#customer').change(function(e) {
                if ($('#customer').val() ==<?php echo $IdCompany; ?>)
                {
                    $('#YourCompany').css('display', 'block');
                }
                else
                {
                    $('#YourCompany').css('display', 'none');
                }
            });
            $('#role_type').change(function() {
                if ($('#role_type').val() == 4 || $('#role_type').val() == 1)
                {
                    $('#div_send_mail').css('display', 'block');
                }
                else
                {
                    $('#div_send_mail').css('display', 'none');
                }
            });


            $('#form_new_user #customer ').change(function() {

                var temp = $('#form_new_user #customer').val();
                change_new_user(temp);
            });

            $('#btn_form_new_user').click(function(e) {
                $('#hid_isuser').val(0);
                $('#form_new_user').submit();
            });
            $("#form_new_user").validate({
                rules: {
                    name: {required: true},
                    password: {required: true, },
                    password2: {equalTo: "#password"},
                    customer: {selectNone: true},
                    mail: {required: true, email: true},
                    role_type: {selectNone: true},
                    customer_add: {selectNone: true},
                    project: {selectNone: true}
                },
                messages:
                        {
                            name: "שם משתמש",
                            password: "סיסמא",
                            password2: "אימות סיסמא",
                            customer: "לקוח",
                            mail: "אימייל",
                            role_type: "תפקיד",
                            customer_add: "לקוח",
                            project: "פרויקט"
                        },
                errorLabelContainer: '#error',
                errorElement: "li",
                submitHandler: function(form)
                {

                    var x = $('#form_new_user #name').val();
                    var form = $('#form_new_user').serialize();
                    isusercustomer(x, $('#SD').val(), form);


                }
            });
        });
    </script>
    <input id="hid_isuser" name="hid_isuser" type="hidden" value="0" />

    <?php
}
if ($_POST['do'] == 'CreateNewUserOfProject') {

    $IDCustomer = $_POST['id_custimer'];
    ?>
    <form id="form_new_user" class="admin_form" name="form_new_user" method="post" action="update.php">
        <h3>יצירת משתמש חדש</h3>
        <input id="hid_new_user" name="hid_new_user" type="hidden"  />
        <fieldset>
            <legend>פרטי משתמש:</legend>
            <div class="form_set">
                <label>שם משתמש:</label>
                <input id="name" name="name" type="text"  />
            </div>
            <div class="form_set">
                <label>סיסמא:</label>
                <input id="password" name="password" type="text"  />
            </div>
            <div class="form_set">
                <label>אימות סיסמא:</label>
                <input id="password2" name="password2" type="text"  />
            </div>
        </fieldset>
        <fieldset>
            <div class="form_set">
                <label>לקוח:</label>
                <select id="customer" name="customer">
                    <option value="<?php echo $IDCustomer; ?>"><?php echo customer::GetNameCustomer($IDCustomer); ?></option>
                </select>
            </div>
            <div class="form_set">
                <label>אימייל:</label>
                <input id="mail" name="mail" type="text"  />
            </div>
            <div class="form_set">
                <label>תפקיד:</label>
                <select id="role_type" name="role_type">
                    <option value="5">איש קשר פרוייקט</option>
                </select>
            </div>
            <div class="form_set">
                <label>שם פרטי:</label>
                <input id="Fname" name="Fname" type="text"  />
            </div>
            <div class="form_set">
                <label>שם משפחה:</label>
                <input id="Lname" name="Lname" type="text"  />
            </div>
            <div class="form_set">
                <label>טלפון:</label>
                <input id="pon" name="pon" type="text"  />
            </div>
            <div class="form_set">
                <label>סלולרי:</label>
                <input id="mobile" name="mobile" type="text"  />
            </div>
            <div class="form_set">
                <div id="div_send_mail">
                    <label>שליחת מייל לכל הודעה חדשה:</label>
                    <input id="send_mail" name="send_mail" type="checkbox" value="1" checked="checked" />
                </div>   
            </div> 
            <div id="YourCompany" class="form_set displayN clearR">
                <label>עובד חברה</label>
                <input type="radio" name="Employee-Friilnsr" value="Employee"  />
                <label>פרילנסר</label>
                <input type="radio" name="Employee-Friilnsr" value="Friilnsr"  />
                <label>לינק לתיק עבודות</label>
                <input name="Portfolio" type="text" />
            </div>     
        </fieldset>


        <input id="btn_form_new_user" name="btn_form_new_user" type="button" value="שלח" />
    </form>

    <div id="error" ><li class="red">* עליך למלא את השדות:</li></div>
    </div>
    <script src="inc/js/jquery.validate.js" type="text/javascript"></script>
    <script>
        jQuery.validator.addMethod("selectNone",
                function(value, element) {
                    if (element.value == "none")
                    {
                        return false;
                    }
                    else
                        return true;
                },
                "Please select an option."
                );
        $(document).ready(function(e) {
            $('#customer').change(function(e) {
                if ($('#customer').val() ==<?php echo $IdCompany; ?>)
                {
                    $('#YourCompany').css('display', 'block');
                }
                else
                {
                    $('#YourCompany').css('display', 'none');
                }
            });
            $('#role_type').change(function() {
                if ($('#role_type').val() == 4 || $('#role_type').val() == 1)
                {
                    $('#div_send_mail').css('display', 'block');
                }
                else
                {
                    $('#div_send_mail').css('display', 'none');
                }
            });


            $('#form_new_user #customer ').change(function() {

                var temp = $('#form_new_user #customer').val();
                change_new_user(temp);
            });

            $('#btn_form_new_user').click(function(e) {
                $('#hid_isuser').val(0);
                $('#form_new_user').submit();
            });
            $("#form_new_user").validate({
                rules: {
                    name: {required: true},
                    password: {required: true, },
                    password2: {equalTo: "#password"},
                    customer: {selectNone: true},
                    mail: {required: true, email: true},
                    role_type: {selectNone: true},
                    customer_add: {selectNone: true},
                    project: {selectNone: true}
                },
                messages:
                        {
                            name: "שם משתמש",
                            password: "סיסמא",
                            password2: "אימות סיסמא",
                            customer: "לקוח",
                            mail: "אימייל",
                            role_type: "תפקיד",
                            customer_add: "לקוח",
                            project: "פרויקט"
                        },
                errorLabelContainer: '#error',
                errorElement: "li",
                submitHandler: function(form)
                {

                    var x = $('#form_new_user #name').val();
                    var form = $('#form_new_user').serialize();
                    isusercustomer(x, $('#customer').val(), form);


                }
            });
        });
    </script>
    <input id="hid_isuser" name="hid_isuser" type="hidden" value="0" />

    <?php
}
if ($_POST['do'] == 'CreateNewUser') {
    $NameUser = new user();
    $NameUser->user_name = $_POST['name'];
    $NameUser->user_password = $_POST['password'];
    $NameUser->user_customer = $_POST['customer'];
    $NameUser->user_mail = $_POST['mail'];
    $NameUser->role_type = $_POST['role_type'];
    if (isset($_POST[''])) {
        $NameUser->send_mail = $_POST['send_mail'];
    } else {
        $NameUser->send_mail = 0;
    }
    $NameUser->Fname = $_POST['Fname'];
    $NameUser->Lname = $_POST['Lname'];
    $NameUser->pon = $_POST['pon'];
    $NameUser->mobile = $_POST['mobile'];
    $NameUser->Insert();
    ?> <input type="hidden" id="hid_name" name="hid_name" value="<?php echo $NameUser->user_name; ?>"  />
    <input name="list[]" type="hidden"  value="<?php echo $NameUser->getuser_id() ?>"/>
    <?php
    return $NameUser->getuser_id();
}
if ($_POST['do'] == 'Delete') {
    $id = $_POST['id'];
    $project = $_POST['project'];
    return permissions::Remove($id, $project);
}

function get_project_status($id_status) {
    $st = sprintf("SELECT * FROM `project_status`");
    $query = mysql_query($st) or die(mysql_error() . ' ' . $st);
    while ($row = mysql_fetch_assoc($query)) {
        $sid = $row['project_status_id'];
        $sname = $row['project_status'];
        if ($sid == $id_status) {
            echo "<option value='$sid' selected='selected'>$sname</option>";
        } else {
            echo "<option value='$sid'>$sname</option>";
        }
    }
}

